package v1beta1

import (
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// OceanfsSpec defines the desired state of OceanfsSpec
type OceanfsSpec struct {
	OwnerId         string      `json:"owner_id,omitempty"`
	CloudResourceId string      `json:"cloudresource_id,omitempty"`
	ProviderRef     ProviderRef `json:"providerRef,omitempty"`
	VolumeName      string      `json:"volumeName,omitempty"`

	Size             int64            `json:"size,omitempty"`
	ResourceAffinity ResourceAffinity `json:"resourceAffinity,omitempty"`
	TenantName       string           `json:"tenantName,omitempty"`
	//+optional
	//+kubebuilder:default:=false
	AlreadyCreated bool `json:"alreadyCreated,omitempty"`
	// +optional
	ShareProtocol ShareProtocolSpec `json:"shareProtocol,omitempty"`
	// +optional
	OrderInfo OrderInfo `json:"orderInfo,omitempty"`
}

type UserPermissionType string //  0: read-only,1: any-control , 2: no-access, 4: read-write
const (
	PermissionReadOnly   UserPermissionType = "ReadOnly"
	PermissionAnyControl UserPermissionType = "AnyControl"
	PermissionNoAccess   UserPermissionType = "NoAccess"
	PermissionReadWrite  UserPermissionType = "ReadWrite"
)

type ShareProtocolSpec struct {
	NFS  ProtocolSpecNfs  `json:"nfs,omitempty"`
	CIFS ProtocolSpecCifs `json:"cifs,omitempty"`
}
type ProtocolSpecNfs struct {
	Enable  bool   `json:"enable,omitempty"`
	Clients string `json:"clients,omitempty"`
}
type ProtocolSpecCifs struct {
	Enable        bool                   `json:"enable,omitempty"`
	ShareAccounts []SpecCifsShareAccount `json:"ShareAccounts,omitempty"`
}
type SpecCifsShareAccount struct {
	UserName   string             `json:"userName,omitempty"`
	Password   string             `json:"password,omitempty"`
	Permission UserPermissionType `json:"permission,omitempty"`
}
type AccessValType string

const (
	AccessValReadOnly          AccessValType = "ReadOnly"
	AccessValReadWrite         AccessValType = "ReadWrite"
	AccessValReadWriteNoDelete AccessValType = "ReadWriteNoDelete"
)

type OceanNFS struct {
	Enabled   bool           `json:"enabled,omitempty"`
	Clients   OceanNFSClient `json:"clients,omitempty"`
	ShareId   string         `json:"shareId,omitempty"`
	SharePath string         `json:"sharePath,omitempty"`
	FsId      string         `json:"fsId,omitempty"`
}
type OceanNFSClient struct {
	ClientId  string        `json:"clientId,omitempty"`
	Name      string        `json:"name,omitempty"`
	AccessVal AccessValType `json:"accessVal,omitempty"`
}
type OceanCIFS struct {
	Enabled       bool                    `json:"enabled,omitempty"`
	ShareAccounts []OceanCifsShareAccount `json:"ShareAccounts,omitempty"`
	ShareId       string                  `json:"shareId,omitempty"`
	SharePath     string                  `json:"sharePath,omitempty"`
}
type OceanCifsShareAccount struct {
	UserId     string             `json:"userId,omitempty"`
	UserName   string             `json:"userName,omitempty"`
	Password   string             `json:"password,omitempty"`
	Permission UserPermissionType `json:"permission,omitempty"`
	GroupId    string             `json:"groupId,omitempty"`
	UserType   int                `json:"userType,omitempty"`
	ShareID    string             `json:"ShareID,omitempty"`
	CifsUserId string             `json:"cifsUserId,omitempty"`
}
type ShareProtocolStatus struct {
	NFS  OceanNFS  `json:"nfs,omitempty"`
	CIFS OceanCIFS `json:"cifs,omitempty"`
}

// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +kubebuilder:object:root=true
// +kubebuilder:resource:shortName=ocfs,path=oceanfses
// +kubebuilder:subresource:status

// Oceanfs is the Schema for the OceanfsSpec API
type Oceanfs struct {
	metav1.TypeMeta   `json:",inline"`
	metav1.ObjectMeta `json:"metadata,omitempty"`

	Spec   OceanfsSpec   `json:"spec,omitempty"`
	Status OceanfsStatus `json:"status,omitempty"`
}

type OceanfsStatus struct {
	Phase         OceanfsPhaseType `json:"phase,omitempty"`
	Size          int64            `json:"size,omitempty"`
	Path          string           `json:"path,omitempty"`
	AvailableSize int64            `json:"availableSize,omitempty"`
	QuotaInfo     QuotaInfo        `json:"quotaInfo,omitempty"`
	// +optional
	SubStatus FileVolumeSubStatusType `json:"subStatus,omitempty"`
	// +optional
	Conditions []Condition `json:"conditions,omitempty"`
	// +optional
	ShareProtocol ShareProtocolStatus `json:"shareProtocol"`
	// +optional
	UpdateStatus UpdateStatus `json:"updateStatus,omitempty"`
	// +optional
	Reason string `json:"reason,omitempty"`
	// +optional
	MountedAt map[string]string `json:"mountedAt,omitempty"`
}
type UpdateStatus struct {
	Status     UpdateStatusType `json:"status,omitempty"`
	Reason     string           `json:"reason,omitempty"`
	UpdateTime metav1.Time      `json:"updateTime,omitempty"`
}
type QuotaInfo struct {
	QuotaId     string `json:"quotaId,omitempty"`
	HardLimit   int64  `json:"hardLimit,omitempty"`
	SoftLimit   int64  `json:"softLimit,omitempty"`
	AdviseLimit int64  `json:"adviseLimit,omitempty"`
	AmountUsed  int64  `json:"amountUsed,omitempty"`
}
type OceanfsPhaseType string

const (
	OceanfsCreatingPhase OceanfsPhaseType = "Creating"
	OceanfsReadyPhase    OceanfsPhaseType = "Ready"
	OceanfsFailedPhase   OceanfsPhaseType = "Failed"
	OceanfsPendingPhase  OceanfsPhaseType = "Pending"
	OceanfsCreateFailed  OceanfsPhaseType = "CreateFailed"
)

type UpdateStatusType string

const (
	OceanfsUpdateStatusUpdating UpdateStatusType = "Updating"
	OceanfsUpdateStatusReady    UpdateStatusType = "Updated"
	OceanfsUpdateStatusFailed   UpdateStatusType = "UpdateFailed"
)

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// OceanfsList contains a list of OceanfsSpec item
type OceanfsList struct {
	metav1.TypeMeta `json:",inline"`
	metav1.ListMeta `json:"metadata,omitempty"`
	Items           []Oceanfs `json:"items"`
}
